package com.fhz.mvitest

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import androidx.activity.viewModels
import androidx.lifecycle.lifecycleScope
import com.fhz.mvitest.intent.BannerIntent
import com.fhz.mvitest.state.BannerUIState
import com.fhz.mvitest.viewmodel.BannerViewModel
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {

    private val veiwmodel: BannerViewModel by viewModels()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        lifecycleScope.launch{
            veiwmodel.channel.send(BannerIntent.GetBannerList)
        }

        lifecycleScope.launch {
            veiwmodel.state.collect{
                when(it){
                    is BannerUIState.Success -> {
                        println("成功")
                        println(it.banner.data.size)
                    }
                    is BannerUIState.Fail -> {
                        println("失败")
                    }
                    else -> {
                        println("其他")
                    }
                }
            }
        }


    }
}